# 编写分页器
from collections import OrderedDict

from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class MyUserPage(PageNumberPagination):
    # 页码
    page_query_param = 'page'
    # 每页数据量
    page_size_query_param = 'pagesize'


    # 重写返回方法
    def get_paginated_response(self, data):
        return Response(OrderedDict([
            ('counts', self.page.paginator.count),
            ('lists', data),
            ('page', self.page.number),
            ('pages', self.page.paginator.num_pages),
            ('pagesize', self.max_page_size),
        ]))

